<%--***************************************
*
*环讯
* 
***************************************--%>
<%@ page import="
	java.util.*,
	java.text.*,
	com.probiz.estore.system.util.TranslateService,
	com.probiz.estore.common.model.order.SalesOrder,
	com.probiz.estore.common.model.system.PaymentGateway,
	com.probiz.estore.common.helper.ConfigUtil"
	contentType="text/html; charset=UTF-8"%>
	
<%
	request.setCharacterEncoding("gb2312");
	SalesOrder salesOrder = (SalesOrder) request.getAttribute("salesOrder");
	PaymentGateway paymentGateway = (PaymentGateway) request.getAttribute("paymentGateway");
	request.setAttribute("paymentGateway",paymentGateway);
	HashMap paramMap = paymentGateway.getConfigData();
	
	//-----------------------start: 账户信息------------------------------------------
	String merCode ="";
	String merCert ="";
	String currency="";
	String language="";
	String type="";
	String retType="";
	if (paramMap != null) {
		merCode = paramMap.get("merCode").toString().trim();		//商户号
		merCert = paramMap.get("merCert").toString().trim();		//商户证书
		currency = paramMap.get("currency").toString().trim();		//币种
		language = paramMap.get("language").toString().trim();		//语言
		retType = paramMap.get("retType").toString().trim();		//返回方式 1 user server return type 在真正的环境下，该类型的测试返回地址才能正确访问
		type = paramMap.get("type").toString().trim(); 				//接入模式
	}
	//-----------------------end:   账户信息------------------------------------------
	
	//-----------------------start: 配置信息------------------------------------------
	String serverUrl= ConfigUtil.getInstance().getStoreFrontSiteUrl()+ "/system/payment/ips_response.html?server=true";  //Server to Server返回页面
	String returnUrl= ConfigUtil.getInstance().getStoreFrontSiteUrl()+ "/system/payment/ips_response.html";  			 //支付成功返回URL
	String failUrl= ConfigUtil.getInstance().getStoreFrontSiteUrl()+ "/system/payment/ips_response.html";  			     //支付失败返回URL
	String errorUrl= ConfigUtil.getInstance().getStoreFrontSiteUrl()+ "/system/payment/ips_response.html";  			 //支付错误返回URL
	String requestUrl;    //提交地址
	if(type.equals("1")){
		requestUrl="https://pay.ips.com.cn/ipayment.aspx";
	}else{
		requestUrl="http://pay.ips.net.cn/ipayment.aspx";		
	}
	//-----------------------end:   配置信息------------------------------------------
	
	//-----------------------start: 业务信息------------------------------------------
	DecimalFormat df= new DecimalFormat("0.00");
	String amount = df.format(salesOrder.getUnPaidAmount());			//支付金额 注意测试环境，金额必需提高
	SimpleDateFormat sdf= new SimpleDateFormat("yyyyMMdd");
	String createTime = sdf.format(salesOrder.getCreateTime());			//下单时间
	String orderNo = salesOrder.getOrderNo();							//订单号
	//String orderEncodeType = "0";										//######如果使用不加密，不需要填signMD5，使用md5加密会报签名错######
	String orderEncodeType = "2";										//订单支付加密方式 0=不加密 2=md5 9=错误
	String retEncodeType = "12";										//交易返回加密方式 10=老接口 11=md5withRsa 12=md5 9=错误
	StringBuffer sb = new StringBuffer();
	sb.append(orderNo).append(amount).append(createTime).append(currency).append(merCert);
	//String signMD5 = TranslateService.md5Translate(sb.toString()).toLowerCase();
	
	//订单支付接口的Md5摘要，原文=【订单编号】+【订单金额】+【订单日期】+【币种】+【商户内部证书字符串】
	System.out.println("orginal:"+sb.toString());
	cryptix.jce.provider.MD5 b=new cryptix.jce.provider.MD5();
	String signMD5 = b.toMD5(sb.toString()).toLowerCase(); 
	System.out.println("MD5:"+signMD5);
	//-----------------------end: 	业务信息------------------------------------------

%>

 <div style="display:none">
	<form name="paymentGatewayForm" method="post" action="<%=requestUrl%>">
		<input type="hidden" name="Mer_Code" value="<%=merCode%>">
		<input type="hidden" name="Billno"  value="<%=orderNo%>">
		<input type="hidden" name="Currency_Type" value="<%=currency%>">
		<input type="hidden" name="Lang" value="<%=language%>">
		<input type="hidden" name="Amount" value="<%=amount%>">
		<input type="hidden" name="Date" value="<%=createTime%>">
		<input type="hidden" name="Attach" value="">
		<input type="hidden" name="OrderEncodeType" value="<%=orderEncodeType%>">
		<input type="hidden" name="RetEncodeType" value="<%=retEncodeType%>">	
		<input type="hidden" name="Merchanturl" value="<%=returnUrl%>">
		<input type="hidden" name="RetType" value="<%=retType%>">
		<input type="hidden" name="ServerUrl" value="<%=serverUrl%>">
		<input type="hidden" name="SignMD5" value="<%=signMD5%>">
		<%-- 
		<input type="hidden" name="SignMD5" value="">  <%--######如果使用不加密，不需要填signMD5，使用md5加密会报签名错###### --%>
		--%>
	</form>
 </div>

<script type="text/javascript">
$j(document).ready(function () {
	document.forms["paymentGatewayForm"].submit();
});
</script>

<%@ include file="./include/payOrderTips.jspf" %>